<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>社会关系/家庭成员</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body>
        <form id="cust_cst_np_social_rl_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
                    <div class="label">关系</div>
                    <div class="field">
                        <select name=rlTypCd id="rlTypCd" data-value="" validate="{required:true, select: true}">
			            	<c:forEach items="${searchSelectRlTypCdList }" var="kv" begin="0" step="1" varStatus="status">
								<c:if test="${status.index == 0}">
								     <option value="${kv.key }" checked >${kv.value }</option>
								</c:if>
							<c:if test="${status.index != 0}">
								    <option value="${kv.key }">${kv.value }</option>
								</c:if>
							</c:forEach>
			            </select>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">姓名</div>
                    <div class="field">
                        <input name="rlNm" id="rlNm" type="text" class="ui-textbox" value="" validate="{required:true,nmcharacter:true,maxlength:20}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
			             <div class="label">性别</div>
			             <div class="field">
			                  <c:forEach items="${searchSelectGenderCdList }" var="kv" begin="0" step="1" varStatus="status">
			                       <c:if test="${status.index == 0}">
			                           <input type="radio" value="${kv.key }" name="genderCd" checked />${kv.value }	
			                       </c:if>
								   <c:if test="${status.index != 0}">
			                           <input type="radio" value="${kv.key }" name="genderCd" />${kv.value }	
			                       </c:if>
							  </c:forEach>
			              </div>
			     </div>
                <div class="fieldBox col_50">
                    <div class="label">手机号</div>
                    <div class="field">
                        <input name="mp" id="mp" type="text" class="ui-textbox" value="" validate="{maxlength:20, mobile: true,required:true}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">工作单位</div>
                    <div class="field">
                        <input name="workPlc" id="workPlc" type="text" class="ui-textbox" value="" validate="{maxlength:100}">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">职务</div>
                    <div class="field">
                        <input name="pos" id="pos" type="text" class="ui-textbox" value=""  validate="{maxlength:100}">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">单位电话</div>
                    <div class="field">
                        <input name="tel" id="tel" type="text" class="ui-textbox" value="" validate="{maxlength:20, phone: true}">
                    </div>
                </div>
                <div class="fieldBox col_50">
			        <div class="label">证件类型</div>
			          <div class="field">
			         	 <select name="certTypCd" id="certTypCd" data-value="" validate="{required:true, select: true}">
			            	<c:forEach items="${searchSelectCertTypCdList }" var="kv" begin="0" step="1" varStatus="status">
								<c:if test="${status.index == 0}">
								     <option value="${kv.key }" checked >${kv.value }</option>
								</c:if>
							<c:if test="${status.index != 0}">
								    <option value="${kv.key }">${kv.value }</option>
								</c:if>
							</c:forEach>
			             </select>
			             <span id="certNoRequired1" class="requiredSymbol">*</span>
			         </div>
			       </div>
                <div class="fieldBox col_50">
                    <div class="label">证件号</div>
                    <div class="field">
                        <input name="certNo" id="certNo" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:30 }">
                        <span id="certNoRequired2" class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">通讯地址邮编</div>
                    <div class="field">
                        <input name="zipNo" id="zipNo" type="text" class="ui-textbox" value="" validate="{required:false,zipCode:true}">
                    </div>
                </div>

                <div class="fieldBox col_50">
                    <div class="label">是否实际还款人</div>
                    <div class="field">
                        <select name=isActualPayer id="isActualPayer" data-value=" ">
                            <option value=" ">请选择</option>
                            <c:forEach items="${searchIsActualPayerCdList }" var="kv">
                                <option value="${kv.key }">${kv.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div id = "PO_formSet" class="fieldBox col_50">
                    <div class="label">民族</div>
                    <div class="field">
                        <select name="nation" id="nation" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                            <option value="">请选择</option>
                            <c:forEach items="${searchNationCdList }" var="kv">
                                <option value="${kv.key }">${kv.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                 <div class="fieldBox col_100">
                    <div class="label">身份证地址</div>
                    <div class="field">
                        <input name="idAddr" id="idAddr" type="text" class="ui-textbox" value="" validate="{maxlength:100 }">
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">现居住地</div>
                    <div class="field">
                        <input name="homeAddr" id="homeAddr" type="text" class="ui-textbox" value="" validate="{maxlength:100 }">
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">单位地址</div>
                    <div class="field">
                        <input name="workAddr" id="workAddr" type="text" class="ui-textbox" value="" validate="{maxlength:100 }">
                    </div>
                </div>
                 <div class="fieldBox col_100">
                    <div class="label">通讯地址</div>
                    <div class="field">
                        <input name="postAddr" id="postAddr" type="text" class="ui-textbox" value="" validate="{maxlength:100 }">
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">备注</div>
                    <div class="field">
                        <textarea name="rlRem" id="rlRem" rows="4" class="l-textarea" style="width:99%" validate="{maxlength:150}"></textarea>
                    </div>
                </div>
                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name=cstId id="cstId" type="text" class="ui-textbox" value="${cstId}">
		              <input name=rId id="rId" type="text" class="ui-textbox" value="${rId}">
		          </div>
		        </div>
            </div>
        </form>
	<script>
		$(function() {
		   $("#cust_cst_np_social_rl_form").ligerForm({
                validate: true
           });
            $("#PO_formSet").addClass('Hide');
	       initData();
	       nationCdEvent(); //初始化关系事件
	       isCertNoRequired(); //设置身份证号是否必填校验
	       //关系类型绑定change事件
	       $("#rlTypCd").change(function(event) {
	    	   isCertNoRequired();
			});
		});
		
		
		//定义父级调用事件
		frameElement.dialog.onOk = function () {
            save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}

		//保存
		function save(){
			var ligerForm = liger.get("cust_cst_np_social_rl_form");
            if (!ligerForm.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            
            var rId = $("#rId").val();
            var url = '<%=path%>/customer/cstnpsocialrl/add.do';
            if(rId != ""){
            	url = '<%=path%>/customer/cstnpsocialrl/modify.do';
            	data["id"]= rId;
            }
            var genderCd = $('input[name="genderCd"]:checked ').val();
            data["genderCd"] = genderCd;

            var wait_dialog= $.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });
            
            //设置客户ID
            var cstId = $("#cstId").val();
            data["cstId"]= cstId;
            $.ajax({
        		type: 'post',
        		dataType:'json',
        		data:data,
        		url: url,
        		success:function(msg){
        			wait_dialog.close();
        			 if(msg.success == 1){
        				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
        				 debugger
        				 if(msg.data){
                             $(parent.mp1).val(msg.data);
                         }
                         parent.npSocialRlGrid.setParm("cstId",cstId);
        				 parent.npSocialRlGrid.reload();
        				 frameElement.dialog.close();
        			 }else{
        				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
        			 }
        		}
        	});
		}
		
		
		
		function initData(){
			var rId = $("#rId").val();
	    	if(!rId)return;
	    	 var wait_dialog= $.ligerDialog.SQalert({
		            content: LogUtils.LOG_CMM_LOADING,
		            SQ_type: "waitting",
		            onClose: function () {
		            }
		        });
	    	var _url = '<%=path%>/customer/cstnpsocialrl/getById.do';
	    	$.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{id:rId},
	    		url: _url,
	    		success:function(msg){
	    			wait_dialog.close();
	    			 if(msg.success == 1){
	    				 setData(msg.data);//设置数据
	    			 }else{
	    				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			 }
	    		}
	    	});
    	}
		
		//设置页面数据
	    function setData(data){
	    	var form = new liger.get("cust_cst_np_social_rl_form");
	    	form.setData({
	    		rlTypCd:data.rlTypCd,
	    		rlNm:data.rlNm,
	    		workPlc:data.workPlc,
	    		pos:data.pos,
	    		mp:data.mp,
	    		tel:data.tel,
	    		certTypCd:data.certTypCd,
	    		certNo:data.certNo,
	    		homeAddr:data.homeAddr,
	    		workAddr:data.workAddr,
	    		zipNo:data.zipNo,
	    		idAddr:data.idAddr,
	    		postAddr:data.postAddr,
	    		rlRem:data.rlRem,
                isActualPayer:data.isActualPayer,
	    		nation:data.nation,
                nationNm:data.nationNm
	    	});
	    	//性别单独赋值
        	$("input[name='genderCd'][value="+data.genderCd+"]").prev(".l-radio").click();
        	isCertNoRequired(); //设置身份证号是否必填校验
		};
		
		//设置身份证号是否必填校验-JL
		function isCertNoRequired(){
			var rl_formSet = liger.get("cust_cst_np_social_rl_form");
        	var rlTypCdVal = $("#rlTypCd").val();
        	console.log("关系类型=" + rlTypCdVal);
        	if (rlTypCdVal == "5" || rlTypCdVal == "7") {
				$("#certNoRequired1").removeClass('Hide');
				$("#certNoRequired2").removeClass('Hide');
				// rl_formSet.setFieldValidate("certNo", {required:true, maxlength:30 });
        	}else{
        		$("#certNoRequired1").addClass('Hide');
        		$("#certNoRequired2").addClass('Hide');
        		// rl_formSet.setFieldValidate("certNo", {required:false, maxlength:30});
        	}
		}

        //婚姻情况下拉事件
        function nationCdEvent(){
		    debugger;
            $("#rlTypCd").change(function(event) {
                var marriageState_val=$(this).val();
                var formSet1=liger.get("cust_cst_np_social_rl_form");
                //alert(marriageState_val);
                if (marriageState_val=='5') {
                    $("#PO_formSet").removeClass('Hide');
                    $("#PO_formSet").ligerForm({validate: true})
                    // formSet1.setFieldValidate("nation", {required: true, nmcharacter:true});
                    SetIframe_height();
                }else{
                    $("#PO_formSet").addClass('Hide');
                    $("#PO_formSet").ligerForm({validate: false})
                    // formSet1.setFieldValidate("nation", {required: false, nmcharacter:true});
                };
            });
        };
    </script>
</body>
</html>